package com.example.zzh.controller;

import com.example.zzh.service.ZzhDepotHeadService;
import com.example.zzh.utils.Result;
import com.example.zzh.utils.ResultGenerator;
import com.example.zzh.utils.TimeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述
 *
 * @author: ZhangZhenHao
 * @date: 2023年12月30日 9:36
 */
@Api(tags = "金额报表")
@RestController
@RequestMapping("/zzh-money-char")
public class ZzhMoneyCharController {
    @Autowired
    private ZzhDepotHeadService zzhDepotHeadService;

    @PostMapping("/list")
    @ApiOperation(value = "查询金额量", notes = "金额量")
    public Result list(@RequestBody Map<String,Object> params) {
        Map<String,Integer> data=new HashMap<>();
        //当日采购
        int nowDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",0),TimeUtils.dayTime("end",0),"采购");
        //当日销售
        int nowDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",0),TimeUtils.dayTime("end",0),"销售");
        //当月采购
        int nowMonthCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",0),TimeUtils.monthTime("end",0),"采购");
        //当月销售
        int nowMonthXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",0),TimeUtils.monthTime("end",0),"销售");
        //昨日采购
        int yesterDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",1),TimeUtils.dayTime("end",1),"采购");
        //昨日销售
        int yesterDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",1),TimeUtils.dayTime("end",1),"销售");
        //昨月采购
        int yesterMonthCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",1),TimeUtils.monthTime("end",1),"采购");
        //昨月销售
        int yesterMonthXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",1),TimeUtils.monthTime("end",1),"销售");
        data.put("nowDayCGNumber",nowDayCGNumber);
        data.put("nowDayXSNumber",nowDayXSNumber);
        data.put("nowMonthCGNumber",nowMonthCGNumber);
        data.put("nowMonthXSNumber",nowMonthXSNumber);
        data.put("yesterDayCGNumber",yesterDayCGNumber);
        data.put("yesterDayXSNumber",yesterDayXSNumber);
        data.put("yesterMonthCGNumber",yesterMonthCGNumber);
        data.put("yesterMonthXSNumber",yesterMonthXSNumber);
        System.out.println(data.toString());
        return ResultGenerator.genSuccessResult(data);
    }

    @PostMapping("/week")
    @ApiOperation(value = "查询近七天库存量", notes = "近七天库存量")
    public Result week(){
        // 创建一个Map
        Map<String, List<?>> listMap = new HashMap<>();
        // 创建采购列表
        List<Integer> CGList = new ArrayList<>();

        //近七天采购
        int oneDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",6),TimeUtils.dayTime("end",6),"采购");
        int twoDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",5),TimeUtils.dayTime("end",5),"采购");
        int threeDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",4),TimeUtils.dayTime("end",4),"采购");
        int fourDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",3),TimeUtils.dayTime("end",3),"采购");
        int fiveDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",2),TimeUtils.dayTime("end",2),"采购");
        int sixDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",1),TimeUtils.dayTime("end",1),"采购");
        int sevenDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",0),TimeUtils.dayTime("end",0),"采购");
        CGList.add(oneDayCGNumber);
        CGList.add(twoDayCGNumber);
        CGList.add(threeDayCGNumber);
        CGList.add(fourDayCGNumber);
        CGList.add(fiveDayCGNumber);
        CGList.add(sixDayCGNumber);
        CGList.add(sevenDayCGNumber);
        listMap.put("CGList",CGList);

        // 创建销售列表
        List<Integer> XSList = new ArrayList<>();
        int oneDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",6),TimeUtils.dayTime("end",6),"销售");
        int twoDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",5),TimeUtils.dayTime("end",5),"销售");
        int threeDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",4),TimeUtils.dayTime("end",4),"销售");
        int fourDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",3),TimeUtils.dayTime("end",3),"销售");
        int fiveDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",2),TimeUtils.dayTime("end",2),"销售");
        int sixDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",1),TimeUtils.dayTime("end",1),"销售");
        int sevenDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.dayTime("start",0),TimeUtils.dayTime("end",0),"销售");
        XSList.add(oneDayXSNumber);
        XSList.add(twoDayXSNumber);
        XSList.add(threeDayXSNumber);
        XSList.add(fourDayXSNumber);
        XSList.add(fiveDayXSNumber);
        XSList.add(sixDayXSNumber);
        XSList.add(sevenDayXSNumber);
        listMap.put("XSList",XSList);

        listMap.put("weekList",TimeUtils.weekList());
        return ResultGenerator.genSuccessResult(listMap);
    }

    @PostMapping("/month")
    @ApiOperation(value = "查询近七月库存量", notes = "近七月库存量")
    public Result month(){
        // 创建一个Map
        Map<String, List<?>> listMap = new HashMap<>();
        // 创建采购列表
        List<Integer> CGList = new ArrayList<>();

        //近七天采购
        int oneDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",6),TimeUtils.monthTime("end",6),"采购");
        int twoDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",5),TimeUtils.monthTime("end",5),"采购");
        int threeDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",4),TimeUtils.monthTime("end",4),"采购");
        int fourDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",3),TimeUtils.monthTime("end",3),"采购");
        int fiveDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",2),TimeUtils.monthTime("end",2),"采购");
        int sixDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",1),TimeUtils.monthTime("end",1),"采购");
        int sevenDayCGNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",0),TimeUtils.monthTime("end",0),"采购");
        CGList.add(oneDayCGNumber);
        CGList.add(twoDayCGNumber);
        CGList.add(threeDayCGNumber);
        CGList.add(fourDayCGNumber);
        CGList.add(fiveDayCGNumber);
        CGList.add(sixDayCGNumber);
        CGList.add(sevenDayCGNumber);
        listMap.put("monthCGList",CGList);

        // 创建销售列表
        List<Integer> XSList = new ArrayList<>();
        int oneDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",6),TimeUtils.monthTime("end",6),"销售");
        int twoDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",5),TimeUtils.monthTime("end",5),"销售");
        int threeDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",4),TimeUtils.monthTime("end",4),"销售");
        int fourDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",3),TimeUtils.monthTime("end",3),"销售");
        int fiveDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",2),TimeUtils.monthTime("end",2),"销售");
        int sixDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",1),TimeUtils.monthTime("end",1),"销售");
        int sevenDayXSNumber = zzhDepotHeadService.selectMoney(TimeUtils.monthTime("start",0),TimeUtils.monthTime("end",0),"销售");
        XSList.add(oneDayXSNumber);
        XSList.add(twoDayXSNumber);
        XSList.add(threeDayXSNumber);
        XSList.add(fourDayXSNumber);
        XSList.add(fiveDayXSNumber);
        XSList.add(sixDayXSNumber);
        XSList.add(sevenDayXSNumber);
        listMap.put("monthXSList",XSList);

        listMap.put("monthList",TimeUtils.monthList());
        System.out.println("listMap"+listMap.toString());
        return ResultGenerator.genSuccessResult(listMap);
    }

}
